home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / ZIP_1_0.lha / src / math.c < prev    next >
C/C++ Source or Header  |  1992-10-13  |  3KB  |  287 lines

  1. /*
  2.  * math.c
  3.  *
  4.  * Arithmetic, compare and logical instructions
  5.  *
  6.  * Mark Howell 28-Jul-1992 V1.0
  7.  *
  8.  */
  9.  
  10. #include "ztypes.h"
  11.  
  12. /*
  13.  * add
  14.  *
  15.  * Add two operands
  16.  *
  17.  */
  18.  
  19. #ifdef __STDC__
  20. void add (zword_t a, zword_t b)
  21. #else
  22. void add (a, b)
  23. zword_t a, b;
  24. #endif
  25. {
  26.  
  27.     store_operand (a + b);
  28.  
  29. }/* add */
  30.  
  31. /*
  32.  * subtract
  33.  *
  34.  * Subtract two operands
  35.  *
  36.  */
  37.  
  38. #ifdef __STDC__
  39. void subtract (zword_t a, zword_t b)
  40. #else
  41. void subtract (a, b)
  42. zword_t a, b;
  43. #endif
  44. {
  45.  
  46.     store_operand (a - b);
  47.  
  48. }/* subtract */
  49.  
  50. /*
  51.  * multiply
  52.  *
  53.  * Multiply two operands
  54.  *
  55.  */
  56.  
  57. #ifdef __STDC__
  58. void multiply (zword_t a, zword_t b)
  59. #else
  60. void multiply (a, b)
  61. zword_t a, b;
  62. #endif
  63. {
  64.  
  65.     store_operand (a * b);
  66.  
  67. }/* multiply */
  68.  
  69. /*
  70.  * divide
  71.  *
  72.  * Divide two operands
  73.  *
  74.  */
  75.  
  76. #ifdef __STDC__
  77. void divide (zword_t a, zword_t b)
  78. #else
  79. void divide (a, b)
  80. zword_t a, b;
  81. #endif
  82. {
  83.  
  84.     store_operand (a / b);
  85.  
  86. }/* divide */
  87.  
  88. /*
  89.  * remainder
  90.  *
  91.  * Modulus divide two operands
  92.  *
  93.  */
  94.  
  95. #ifdef __STDC__
  96. void remainder (zword_t a, zword_t b)
  97. #else
  98. void remainder (a, b)
  99. zword_t a, b;
  100. #endif
  101. {
  102.  
  103.     store_operand (a % b);
  104.  
  105. }/* remainder */
  106.  
  107. /*
  108.  * or
  109.  *
  110.  * Logical OR
  111.  *
  112.  */
  113.  
  114. #ifdef __STDC__
  115. void or (zword_t a, zword_t b)
  116. #else
  117. void or (a, b)
  118. zword_t a, b;
  119. #endif
  120. {
  121.  
  122.     store_operand (a | b);
  123.  
  124. }/* or */
  125.  
  126. /*
  127.  * not
  128.  *
  129.  * Logical NOT
  130.  *
  131.  */
  132.  
  133. #ifdef __STDC__
  134. void not (zword_t a)
  135. #else
  136. void not (a)
  137. zword_t a;
  138. #endif
  139. {
  140.  
  141.     store_operand (~a);
  142.  
  143. }/* not */
  144.  
  145. /*
  146.  * and
  147.  *
  148.  * Logical AND
  149.  *
  150.  */
  151.  
  152. #ifdef __STDC__
  153. void and (zword_t a, zword_t b)
  154. #else
  155. void and (a, b)
  156. zword_t a, b;
  157. #endif
  158. {
  159.  
  160.     store_operand (a & b);
  161.  
  162. }/* and */
  163.  
  164. /*
  165.  * random
  166.  *
  167.  * Return random number between 1 and operand
  168.  *
  169.  */
  170.  
  171. #ifdef __STDC__
  172. void random (zword_t a)
  173. #else
  174. void random (a)
  175. zword_t a;
  176. #endif
  177. {
  178.  
  179.     if (a)
  180.         store_operand (((zword_t) rand () % a) + 1);
  181.     else
  182.         store_operand (0);
  183.  
  184. }/* random */
  185.  
  186. /*
  187.  * test
  188.  *
  189.  * Jump if operand 2 bit mask not set in operand 1
  190.  *
  191.  */
  192.  
  193. #ifdef __STDC__
  194. void test (zword_t a, zword_t b)
  195. #else
  196. void test (a, b)
  197. zword_t a, b;
  198. #endif
  199. {
  200.  
  201.     conditional_jump (((~a) & b) == 0);
  202.  
  203. }/* test */
  204.  
  205. /*
  206.  * compare_zero
  207.  *
  208.  * Compare operand against zero
  209.  *
  210.  */
  211.  
  212. #ifdef __STDC__
  213. void compare_zero (zword_t a)
  214. #else
  215. void compare_zero (a)
  216. zword_t a;
  217. #endif
  218. {
  219.  
  220.     conditional_jump (a == 0);
  221.  
  222. }/* compare_zero */
  223.  
  224. /*
  225.  * compare_je
  226.  *
  227.  * Jump if operand 1 is equal to any other operand
  228.  *
  229.  */
  230.  
  231. #ifdef __STDC__
  232. void compare_je (int count, zword_t *operand)
  233. #else
  234. void compare_je (count, operand)
  235. int count;
  236. zword_t *operand;
  237. #endif
  238. {
  239.     int i;
  240.  
  241.     for (i = 1; i < count; i++)
  242.         if (operand[0] == operand[i]) {
  243.             conditional_jump (TRUE);
  244.             return;
  245.         }
  246.     conditional_jump (FALSE);
  247.  
  248. }/* compare_je */
  249.  
  250. /*
  251.  * compare_jl
  252.  *
  253.  * Jump if operand 1 is less than operand 2
  254.  *
  255.  */
  256.  
  257. #ifdef __STDC__
  258. void compare_jl (zword_t a, zword_t b)
  259. #else
  260. void compare_jl (a, b)
  261. zword_t a, b;
  262. #endif
  263. {
  264.  
  265.     conditional_jump ((short) a < (short) b);
  266.  
  267. }/* compare_jl */
  268.  
  269. /*
  270.  * compare_jg
  271.  *
  272.  * Jump if operand 1 is greater than operand 2
  273.  *
  274.  */
  275.  
  276. #ifdef __STDC__
  277. void compare_jg (zword_t a, zword_t b)
  278. #else
  279. void compare_jg (a, b)
  280. zword_t a, b;
  281. #endif
  282. {
  283.  
  284.     conditional_jump ((short) a > (short) b);
  285.  
  286. }/* compare_jg */
  287.